package edu.mse.camel.client.session.team;

import java.util.ArrayList;
import java.util.List;

import edu.mse.camel.client.events.AbstractEvent;
import edu.mse.camel.client.events.EventIDs;
import edu.mse.camel.client.events.IEvent;

public class QueryTeamStatus extends AbstractEvent implements IEvent {

	public class TeamMemberInternal {
		private String id;
		private boolean online;
		private String contact1;
		private String contact2;
		private String role;
		
		public void setId(String id)  {
			this.id = id;
		}
		public String  getId() {
			return id;
		}
		public void setContact1(String contact1) {
			this.contact1 = contact1;
		}
		public String getContact1() {
			return contact1;
		}
		public void setContact2(String contact2) {
			this.contact2 = contact2;
		}
		public String getContact2() {
			return contact2;
		}
		public boolean isOnline() {
			return online;
		}
		public void setOnline(boolean online) {
			this.online = online;
		}
		public String getMemberRole() {
			return role;
		}
		public void setMemberRole(String role) {
			this.role = role;
		}
	}
	
	private List<TeamMemberInternal> members = new ArrayList<TeamMemberInternal>();	
	
	/**
	 * This method is used only to speak with the server in the
	 * server library. Should not be used anywhere else.
	 * 
	 * @return
	 */
	public List<TeamMemberInternal> getTeamMemberList() {
		return members;
	}
	
	/**
	 * This can be used to get the new team member list as defined in the 
	 * core plugin 
	 * @see ITeamMember
	 *  
	 * @return
	 */
	public List<ITeamMember> getITeamMembers() {
		List<ITeamMember> convertedlist = new ArrayList<ITeamMember>();
		for (TeamMemberInternal aMember : members) {
			if (aMember.getId().equals(TeamList.getInstance().getMe().getName())) {
				continue;
			}
			ITeamMember newMember = null;
			if (aMember.isOnline()) {
				newMember = new TeamMember(
					aMember.getId(), 
					aMember.getContact1(),
					TEAMMEMBER_STATUS.ONLINE,
					false);
			} else {
				newMember = new TeamMember(
						aMember.getId(), 
						aMember.getContact1(),
						TEAMMEMBER_STATUS.OFFLINE,
						false);
			}
			convertedlist.add(newMember);
		}
		return convertedlist;
	}
	
	public TeamMemberInternal getNewTeamMemberList()
	{
		return new TeamMemberInternal();
	}
	@Override
	public String getEventID() {
		return EventIDs.QUERY_TEAM_STATUS_EVENT;
	}
}
